Skip to content

One Hessian cover per sweep, and cheaper CurvatureScales - #73

Merged
timholy merged 5 commits into
mainfrom
teh/merge-select
Nov 14, 2026
Merged

timholy merged 5 commits into
mainfrom
teh/merge-select

Conversation

@timholy

@timholy timholy commented Nov 14, 2026

Copy link
Copy Markdown
Member

cover_hessian(CoverOnly(), ...) and cover_nls now return one cover per sweep, chosen by a merge keyword: SumMerge() (the default, the certified sum cover) or SignAveragedMerge() (the sign-averaged cover). The result holds it in the field h (for least squares, h and h_gn) and records the rule as its third type parameter, e.g. HessianCover{T, M, R}. A caller that wants both covers runs two sweeps of about the same cost each.

Breaking: the fields h_sum and h_var of HessianCover, and h_var and h_var_gn of NLSCover and NLSDiagnostics, are removed. HessianDiagnostics is unchanged. SumMerge and SignAveragedMerge are now exported and MergeRule is public. The package version is still 1.0.0.

CurvatureScales also costs less:

  • each cover derives its scales from covers of its own kind, so the sign-averaged cover no longer pays for a sum sweep of the drop pass, and the two covers of a program may split a guarded block differently;
  • each round re-splits only the blocks the drop pass dropped and adds the change to the drop pass's cover in one reverse sweep, instead of repeating the whole cover sweep;
  • the forward sweeps that propagate the derived scales visit only the ancestors of the guarded blocks' parents.

Without guarded blocks, the gradient, the sum cover and nguarded are unchanged bit for bit; the sign-averaged cover can change in its last bit. With CurvatureScales, the sum cover agrees with a full sweep under the same scales to within rounding, and on interval tapes the change added to the drop pass's cover is rounded upward, so the cover stays certified.

Commits, in order:

  1. Move the merge rules into src/mergerules.jl (no change in behavior).
  2. Select the Hessian cover with the merge keyword.
  3. Derive each cover's curvature scales from covers of its own kind.
  4. Recompute only the guarded blocks under derived scales.
  5. Restrict the scale propagation to the ancestor cone of the guarded blocks' parents.

🤖 Generated with Claude Code

MergeRule and its four rules move unchanged from jacobian.jl into
mergerules.jl, which is included before covers.jl, so that every
file of the package can name them.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
cover_hessian(CoverOnly(), ...) and cover_nls take
`merge = SumMerge()`, the default, or `merge = SignAveragedMerge()`,
and return the selected cover as the field `h`. The rule is the third
type parameter of the result, HessianCover{T, M, R}, NLSCover{T, M, R}
or NLSDiagnostics{T, M, R}, which the keyword makes inferrable; the
results carry no h_sum/h_var or h_var/h_var_gn fields. Any other rule
throws. cover_hessian(WithDiagnostics(), ...) returns the sum cover
and refuses any rule but SumMerge, naming CoverOnly(). SumMerge and
SignAveragedMerge are exported and MergeRule is public.

The CoverOnly sweep carries the adjoint and the one selected channel.
It forms the absolute adjoint only at nodes with second partials, and
tests a node's channel for finiteness once instead of testing every
zero partial. The gradient, the sum cover and nguarded are unchanged
bit for bit; the sign-averaged cover can change in its last bit where
a first partial is exactly zero, which now enters the `hypot` as a
zero term.

With CurvatureScales, the scales still derive from sum covers, so the
sign-averaged cover of a program with guarded blocks adds one sum
sweep of the drop pass.

For least squares, the sign-averaged covers do not depend on
`ngroups`, and cover_nls refuses `ngroups != 1` with them. Under
WithDiagnostics, `check` verifies the sign-averaged h_gn against the
column norms of Utilde.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
With `scales = CurvatureScales()`, the sign-averaged cover now
derives its scales from sign-averaged covers: the drop pass and every
later round sweep the cover the entry point returns. The sign-averaged
cover transforms as the sum cover does, so the scales remain covariant,
and the two covers vanish at the same inputs, so the anchored inputs
are the same. A program with guarded blocks no longer pays for a sum
sweep of the drop pass in addition to its own.

The two covers of one program can now split a guarded block
differently. The sum cover is unchanged.

derived_scales and resolve_scales take the merge rule, and so does
local_covers, which passes it to the derivation and refuses a rule no
sweep can carry; cover_nls passes its own, so its covers derive their
scales from the loss tape's Hessian cover of the same kind. Orderings
between the two covers are documented for covers under the same
declared scales.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Only the guarded blocks read the declared scales, so under
CurvatureScales a round no longer repeats the whole cover sweep. The
drop pass records each block it drops (DroppedBlock) with its parents,
its node and the slot covers the pass gave that node. Each round, the
final one included, splits those nodes alone under the derived scales
(guarded_covers) and adds the change to the drop pass's cover in one
reverse sweep seeded at their parents (raised_cover). Both covers are
linear in their seeds, the sign-averaged cover in their squares, and a
split weight is never below the diagonal weight the drop pass gave the
same slot, so every change is nonnegative.

The forward sweeps of the check of unanchored inputs sum to the first
round's propagated scales, which that round reuses. The rounds also
reuse the drop pass's live_nodes. A program without guarded blocks
still pays only for the empty record.

On the local-covers path (cover_nls, cover_hybrid and the other entry
points built on local_covers), the recomputed slot covers replace the
dropped ones and the seeds are summed in node order as before. Covers
through either path agree with a full sweep under the same scales to
within rounding.

On a tape whose sweeps round upward, such as an interval tape, a
slot's seed rises by an upper bound on the difference of its two
weights (boundsub): exact where Sterbenz's lemma applies, and one step
above the nearest-rounded difference otherwise.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Under CurvatureScales, only the parents of the dropped blocks read the
propagated declared scales, so the forward sweeps that form them, in
the check of unanchored inputs and in each round, visit only those
parents' ancestors (ancestor_cone). abs_forward and
sensitivity_scales take the cone. DeclaredScales carries it and throws
if a split asks for a scale outside it.

GuardedRedo records the dropped blocks' parents with their cone, so
derived_scales takes only the CurvatureScales and the GuardedRedo.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
@timholy
timholy merged commit 55b58ab into main Nov 14, 2026
9 checks passed
@timholy
timholy deleted the teh/merge-select branch November 14, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant